//
//  UIButton+addClickBtn.m
//  ANDA_Club
//
//  Created by Lonely丶晏袁杰 on 2020/7/17.
//  Copyright © 2020 Lonely`yyj. All rights reserved.
//

#import "UIButton+addClickBtn.h"
#import <objc/runtime.h>

static void *strKey = &strKey;
@interface UIButton()
@property (copy ,nonatomic) clickBlock yyeInBlock;
@end
@implementation UIButton (addClickBtn)
- (void)addClickForControlEvents:(UIControlEvents)event click:(clickBlock)block {
    self.yyeInBlock = block;
    [self addTarget:self action:@selector(yyeMyClick:) forControlEvents:event];
}

- (void)yyeMyClick:(UIButton *)sender {
    sender.enabled = NO;
    if (self.yyeInBlock) {
        self.yyeInBlock(sender);
    }
    sender.enabled = YES;
}

-(void)setYyeInBlock:(clickBlock)bloack {
    objc_setAssociatedObject(self, &strKey, bloack, OBJC_ASSOCIATION_COPY);
}

-(NSString *)yyeInBlock {
    return objc_getAssociatedObject(self, &strKey);
}
@end
